from selenium.webdriver.common.by import By

from common.base import Base
from common.functions import open_browser


class RegisterPage(Base):
    # 页面网址
    register_url = 'http://139.129.26.163/user.php?act=register'

    # 输入用户名
    def input_username(self, username):
        self.send_keys((By.ID, 'username'), username)

    # 输入email
    def input_email(self, email):
        self.send_keys((By.ID, 'email'), email)

    # 输入密码
    def input_password(self, password1):
        self.send_keys((By.ID, 'password1'), password1)

    # 确认密码
    def confirm_password(self, password2):
        self.send_keys((By.ID, 'conform_password'), password2)

    # 输入qq
    def input_qq(self, qq=''):
        self.send_keys((By.NAME, 'extend_field2'), qq)

    # 输入办公号码
    def input_tel(self, tel=''):
        self.send_keys((By.NAME, 'extend_field3'), tel)

    # 输入家庭号码
    def input_home_phone(self, home_phone=''):
        self.send_keys((By.NAME, 'extend_field4'), home_phone)

    # 输入手机号
    def input_phone(self, phone):
        self.send_keys((By.NAME, 'extend_field5'), phone)

    # 选择密码提示问题
    def select_hint_question(self, index):
        self.select_by_index((By.NAME, 'sel_question'), index)

    # 输入密码问题答案
    def input_answer(self, content):
        self.send_keys((By.NAME, 'passwd_answer'), content)

    # 点击我已阅读并同意
    # def click_agree(self):
    #     self.click((By.NAME, 'agreement'))

    # 点击立即注册
    def click_register(self):
        self.click((By.XPATH, '//input[@name="Submit"]'))


if __name__ == '__main__':
    browser = open_browser()
    case = RegisterPage(browser)
    case.get(case.register_url)
    case.input_username('yangyu')
    case.input_email('1130780712@qq.com')
    case.input_password('123456')
    case.confirm_password('123456')
    case.input_qq('1130780712')
    case.input_tel('84886')
    case.input_home_phone('84886886')
    case.input_phone('18827553053')
    case.select_hint_question(2)
    case.input_answer('我是杨宇')
    # case.click_agree()
    case.click_register()
